import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BruteForceSolution {
    public List<Integer> findSubstring(String s, String[] words) {
        List<Integer> ret = new ArrayList<>();
        int len = words.length;//words中字符串个数
        int strLen = words[0].length();//words中每个字符串的长度
        Map<String, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < len; i++) {
            hashMap.put(words[i], hashMap.getOrDefault(words[i], 0) + 1);
        }
        int sLen = s.length();
        for (int i = 0; i < sLen - len * strLen + 1; i++) {
            boolean flag = true;
            Map<String, Integer> hashMap1 = new HashMap<>();
            for (int j = i; j < len * strLen + i; j += strLen) {
                String subString = s.substring(j, j + strLen);
                hashMap1.put(subString, hashMap1.getOrDefault(subString, 0) + 1);
            }
            if (hashMap.equals(hashMap1)) {
                ret.add(i);
            }
        }
        return ret;
    }
}
